package dao

import (
	"math/rand"
	"server/basic/config"
	"server/basic/model"
	"server/basic/pkg"
	"strconv"
)

func UserLogin(name string) (user model.Users, err error) {
	err = config.DB.Where("username=?", name).Find(&user).Error
	if err != nil {
		return model.Users{}, err
	}
	return user, nil
}

func UserRegister(phone string) (user model.Users, err error) {
	name := strconv.Itoa(rand.Intn(90000) + 10000)
	user = model.Users{

		Username: "用户" + name,
		Password: pkg.Md5("123456"),
		Phone:    phone,
	}
	err = config.DB.Create(&user).Error
	if err != nil {
		return model.Users{}, err
	}
	return user, nil
}
